import type { ID, Timestamp, Language, Theme } from './global';
import type { SearchHistory, ContentType } from './search';

// 用户基本信息
export interface User {
  id: ID;
  username: string;
  email: string;
  avatar?: string;
  displayName?: string;
  bio?: string;
  location?: {
    country: string;
    region: string;
    city: string;
  };
  createdAt: Timestamp;
  lastLoginAt: Timestamp;
  isActive: boolean;
  role: UserRole;
}

// 用户角色
export type UserRole = 'guest' | 'user' | 'premium' | 'admin';

// 用户偏好设置
export interface UserPreferences {
  // 界面设置
  theme: Theme;
  language: Language;
  fontSize: 'small' | 'medium' | 'large';
  
  // 搜索设置
  safeSearch: boolean;
  resultsPerPage: number;
  defaultSort: 'relevance' | 'date' | 'popularity';
  enableVoiceSearch: boolean;
  enableImageSearch: boolean;
  
  // 内容偏好
  preferredContentTypes: ContentType[];
  blockedSources: string[];
  favoriteCategories: string[];
  
  // 隐私设置
  saveSearchHistory: boolean;
  enablePersonalization: boolean;
  shareUsageData: boolean;
  
  // 通知设置
  emailNotifications: boolean;
  pushNotifications: boolean;
  trendingAlerts: boolean;
}

// 用户档案
export interface UserProfile {
  user: User;
  preferences: UserPreferences;
  statistics: UserStatistics;
  subscription?: UserSubscription;
}

// 用户统计信息
export interface UserStatistics {
  totalSearches: number;
  totalClicks: number;
  averageSessionDuration: number; // 秒
  favoriteCategories: Array<{
    category: string;
    count: number;
    percentage: number;
  }>;
  searchHistory: SearchHistory[];
  bookmarks: Bookmark[];
  recentActivity: UserActivity[];
}

// 用户订阅信息
export interface UserSubscription {
  plan: 'free' | 'basic' | 'premium' | 'enterprise';
  status: 'active' | 'inactive' | 'cancelled' | 'expired';
  startDate: Timestamp;
  endDate?: Timestamp;
  features: string[];
  limits: {
    searchesPerDay: number;
    bookmarksLimit: number;
    historyRetention: number; // 天数
  };
}

// 书签
export interface Bookmark {
  id: ID;
  userId: ID;
  title: string;
  url: string;
  description?: string;
  tags: string[];
  category?: string;
  thumbnail?: string;
  createdAt: Timestamp;
  lastAccessedAt?: Timestamp;
  isPublic: boolean;
}

// 用户活动
export interface UserActivity {
  id: ID;
  userId: ID;
  type: 'search' | 'click' | 'bookmark' | 'share' | 'download';
  target: {
    type: 'result' | 'suggestion' | 'bookmark';
    id: ID;
    title: string;
    url?: string;
  };
  metadata?: Record<string, any>;
  timestamp: Timestamp;
  sessionId: string;
}

// 用户会话
export interface UserSession {
  id: string;
  userId?: ID;
  startTime: Timestamp;
  endTime?: Timestamp;
  duration?: number; // 秒
  pageViews: number;
  searches: number;
  clicks: number;
  userAgent: string;
  ipAddress: string;
  location?: {
    country: string;
    region: string;
    city: string;
  };
  referrer?: string;
}

// 用户反馈
export interface UserFeedback {
  id: ID;
  userId: ID;
  type: 'bug' | 'feature' | 'improvement' | 'complaint' | 'praise';
  title: string;
  description: string;
  category?: string;
  priority: 'low' | 'medium' | 'high' | 'critical';
  status: 'open' | 'in_progress' | 'resolved' | 'closed';
  attachments?: string[];
  createdAt: Timestamp;
  updatedAt: Timestamp;
  resolvedAt?: Timestamp;
}

// 用户通知
export interface UserNotification {
  id: ID;
  userId: ID;
  type: 'system' | 'feature' | 'trending' | 'personal';
  title: string;
  message: string;
  actionUrl?: string;
  actionText?: string;
  isRead: boolean;
  createdAt: Timestamp;
  readAt?: Timestamp;
  expiresAt?: Timestamp;
}
